package com.lzy.cloud.ticket.train.controller;

import com.lzy.cloud.ticket.train.facade.InsuranceFacade;
import com.lzy.cloud.ticket.train.request.app.InsuranceOrderAppRequest;
import com.lzy.cloud.ticket.train.response.InsuranceOrderResponse;
import com.lzy.cloud.ticket.train.response.InsuranceResponse;
import com.lzy.cloud.ticket.train.util.ErrorUtil;
import com.lzy.framework.core.ensure.Ensure;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 保险
 *
 * @author lc
 * @version 2018/8/3
 */
@RestController
@RequestMapping(value = "/insurance")
public class TrainInsuranceController extends BaseController {

    @Autowired
    private InsuranceFacade insuranceFacade;

    @Autowired
    private ErrorUtil errorUtil;

    /**
     * 火车票包含的保险订单
     * TODO 未测试
     *
     * @return
     */
    @RequestMapping(value = "/query", method = RequestMethod.POST)
    public InsuranceOrderResponse queryInsuranceOrder(@RequestBody InsuranceOrderAppRequest insuranceOrderAppRequest) {
        InsuranceOrderResponse insuranceOrderResponse = insuranceFacade.queryInsuranceOrder(insuranceOrderAppRequest);
        Ensure.that(insuranceOrderResponse).isNotNull("00010001");
        Ensure.that(errorUtil.toError(insuranceOrderResponse)).isTrue("00010001");
        return insuranceOrderResponse;
    }


    /**
     * 保险产品查询,现没有保险产品
     * TODO 未测试
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public InsuranceResponse queryInsurance() {
        InsuranceResponse insuranceResponse = insuranceFacade.queryInsurance();
        Ensure.that(insuranceResponse).isNotNull("00010001");
        Ensure.that(errorUtil.toError(insuranceResponse)).isTrue("00010001");
        return insuranceResponse;
    }
}
